
//
//  HMStatusCell.m
//  黑马微博-wzy
//
//  Created by Mac on 2017/2/17.
//  Copyright © 2017年 Mac. All rights reserved.
//

#import "HMStatusCell.h"
#import "HMStatusDetailView.h"
#import "HMStatusToolbar.h"
#import "HMStatusFrame.h"

@interface HMStatusCell()
//微博详情 视图
@property (nonatomic, weak) HMStatusDetailView *detailView;
//toolbar 视图
@property (nonatomic, weak) HMStatusToolbar *toolBar;

@end



@implementation HMStatusCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

+ (instancetype)cellWithTableView:(UITableView *)tableView{
   static NSString *ID = @"status";
    HMStatusCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (!cell) {
        cell = [[HMStatusCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
    }
    return cell;
}


- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        //初始化子控件
        //1.添加微博的具体内容
        HMStatusDetailView *detailView = [[HMStatusDetailView alloc] init];
        [self.contentView addSubview:detailView];
        self.detailView = detailView;
        
        //2.添加工具条
        HMStatusToolbar *toolBar = [[HMStatusToolbar alloc] init];
        [self.contentView addSubview:toolBar];
        self.toolBar = toolBar;
        
        //3.cell的设置
        self.backgroundColor = [UIColor clearColor];
    }
    
    return self;
}

//根据传进来的微博数据计算所有控件的尺寸
//重写 statusFrame 的setter方法
- (void)setStatusFrame:(HMStatusFrame *)statusFrame{
    _statusFrame = statusFrame;
    
    //1.计算微博具体内容的frame
    self.detailView.detailFrame = statusFrame.detailFrame;
    
    //2.底部工具条的frame
    self.toolBar.frame = statusFrame.toolbarFrame;
    //将微博数据传递到toolBar中
    self.toolBar.status = statusFrame.status;
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
